
	<fieldset id="cadastroTurma">
		<legend>Cadastro de Turmas</legend>

		<label for="nomeTurma">Nome</label>
		<input type="text" id="nomeEtapa" class="input-xlarge" name="nome" />
		
		<label for="nomeEscola">Escola</label>
		<select id="nomeEscola" class="input-xlarge" name="escola_id">
			<?=$escolas?>
		</select>
		
		<label for="nomeEtapa">Etapa</label>
		<select id="nomeEtapas" class="input-xlarge" name="etapa_id">
			<?=$etapas?>
		</select>
		
		<div style="padding-top: 20px; padding-botton: 10px;">
			<button class="btn btn-primary btn-large" id="salvarButton">Salvar</button>
		</div>

	</fieldset>

	<script type="text/javascript">
		var turma_id = null;

		$(document).ready(function(){
			$("#salvarButton").click(function(){
				var data = form.serialize('cadastroTurma');
				
				if(turma_id != null){
					data['id'] = turma_id;
				}

				var url = "<?= base_url() ?>turma/salvar";
				if(turma_id)
					url = "<?= base_url() ?>turma/atualizar";

				form.submit(base_url + 'turma/salvar',
						    data,
						    'POST');
			});

			load();
		});

		function load(){
			var id = form.loadVar('id');

			if(!id)
				return;

			modal.carregando();

			$.ajax({
				url: base_url + 'turma/show_info_json',
				data: {id: id},
				type: 'GET',
				success: function(result){
					var jsonResult = JSON.parse(result);
					var jsonResult = JSON.parse(result);
					$.each(jsonResult, function(v,i){
						if(v == 'id')
							turma_id = i;

						$('[name=' + v + ']').val(i);
							
					});
					modal.encerrar();
				},
				error: function(){
					modal.message('Erro ao carregar informações');
				}
			});

		
}
	</script>